package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.shopping.dto.ProductInfoDto;
import com.cskaoyan.shopping.form.CheckAllItemRequest;
import com.cskaoyan.shopping.service.ICartService;
import com.cskaoyan.shopping.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ZhangHang @latimer.top
 * @version 1.0.0
 * @description TODO
 * @date 2022/12/3 0:26
 */
@RestController
public class ItemsController {
    @Autowired
    ICartService cartService;

    @Autowired
    IProductService productService;

    @DeleteMapping("/shopping/items/{uid}")
    public ResponseData deleteCheckedItems(@PathVariable("uid") Long userId){
        //cartService
        cartService.deleteCheckedItem(userId);
        return new ResponseUtil<Object>().setData(null);
    }

    @PutMapping("/shopping/items")
    public ResponseData checkAllCartItem(@RequestBody CheckAllItemRequest request){
        cartService.checkAllCartItem(request);
        return new ResponseUtil<String>().setData("成功","success");
    }

    @GetMapping("/shopping/info/item/{productId}")
    public ResponseData itemInfo(@PathVariable("productId") Long productId){
        ProductInfoDto productInfoDto = productService.getItemInfo(productId);
        return new ResponseUtil<ProductInfoDto>().setData(productInfoDto);
    }
}
